import ddf.minim.*;

Minim minim;
AudioPlayer player;
float[] bufferx1,bufferx2;

float gradientStep = 5;

float sunStep = 0.05f,sunX,sunY;

float bruh = 0;

float dampStrength = 0.3,currdamp;

void setup(){
  size(1024,600);
  minim = new Minim(this);
  //player = minim.loadFile("Ridiculon - Home.mp3");
  //player = minim.loadFile("Ludwig, the Holy Blade.mp3");
  player = minim.loadFile("Hyper - Spoiler Original Mix.mp3");
  //player = minim.loadFile("Snow halation.mp3");
  bufferx1 = new float[player.bufferSize()];
  bufferx2 = new float[player.bufferSize()];
  //initialize array components
  for (int i = 0; i < player.bufferSize() - 1; i++)
  {
    bufferx1[i] = 0;
    bufferx2[i] = 0;
  }

  player.play();
}


void draw(){
  
  noStroke();
  fill(255,30);
  
  //gradient fills background
  for(int j = 0;j<width;j += gradientStep){
      fill(map(j,0,800,200,255),map(j,0,800,210,255),map(j,0,800,230,255),30);
      rect(0,j,width,gradientStep);
  }

  //Stores every buffer's damped volume numbers in array
  for (int i = 0; i < player.bufferSize() - 1; i++)
  {
    if(i<player.bufferSize()/20f){
      currdamp = lerp(0.8,dampStrength,(20*i)/player.bufferSize());
    }
    else{
      currdamp = dampStrength;
    }
    float x1 = map( i, 0, player.bufferSize(), 0, width );
    float x2 = map( i+1, 0, player.bufferSize(), 0, width );
    bufferx1[i] = lerp(bufferx1[i],player.left.get(i),currdamp);
    bufferx2[i] = lerp(bufferx2[i],player.right.get(i),currdamp);
    stroke(lerpColor(color(248,140,120),color(120,140,243),(float)i/(float)player.bufferSize()));
    line( x1, 430 + bufferx1[i]*50, x2, 400 + bufferx1[i+1]*50 );
    stroke(lerpColor(color(248,170,120),color(177,127,248),(float)i/(float)player.bufferSize()));
    line( x2, 480 + bufferx2[i]*50, x2, 420 + bufferx2[i+1]*50 );
    stroke(lerpColor(color(157,238,248),color(248,157,157),(float)i/(float)player.bufferSize()));
    line( x1, 540 + bufferx1[i]*50, x2, 470 + bufferx1[i+1]*50 );
    stroke(lerpColor(color(248,234,157),color(248,157,157),(float)i/(float)player.bufferSize()));
    line( x2, 620 + bufferx2[i]*50, x2, 500 + bufferx2[i+1]*50 );
  }
  
  //Sun
  pushMatrix();
  translate(875,110);
  fill(255,220,180);
  rotate(bruh);
  for(float k = 0;k<TWO_PI;k+=sunStep){
    if(k>5.8){
      fill(255,120,100);
    }
    sunX = 150*cos(k)*noise(player.left.get(0));
    sunY = 150*sin(k)*noise(player.right.get(0));
    ellipse(sunX,sunY,3,3);
  }
  translate(-875,-110);
  popMatrix();
  bruh += 0.2;
  if(bruh>TWO_PI){
    bruh = 0;
  } 
}
